﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class AppCode_Admin_RequestDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["userNameAdmin"] == null)
            {
                Response.Redirect("..\\Home\\HomePage.aspx");
            }
        }
        String connect = WebConfigurationManager.ConnectionStrings["ConnectDatabase"].ToString();
        SqlConnection sqlConnect = new SqlConnection(connect);
        SqlDataAdapter sqlda = new SqlDataAdapter("Select RequestId,RequestDate,Empno,PolicyRequestDetails.PolicyId,Policies.PolicyName,Policies.Amount,Policies.Emi,Policies.CompanyId,CompanyDetails.CompanyName From PolicyRequestDetails join Policies " +
                                                   "on Policies.PolicyId=PolicyRequestDetails.PolicyId " +
                                                    "join CompanyDetails " +
                                                    "on CompanyDetails.CompanyId=Policies.CompanyId", sqlConnect);
        DataSet ds = new DataSet();
        sqlda.Fill(ds);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
    }
    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.ToString().Equals("btndelete"))
        {
            String connect = WebConfigurationManager.ConnectionStrings["ConnectDatabase"].ToString();
            SqlConnection sqlConnect = new SqlConnection(connect);
            sqlConnect.Open();
            int index = Convert.ToInt32(e.CommandArgument);
            SqlCommand sqlCommand = new SqlCommand("Delete from PolicyRequestDetails where RequestId=" + index, sqlConnect);
            sqlCommand.ExecuteNonQuery();
            sqlConnect.Close();
            this.Page_Load(null,null);
        }
    }
}